package com.kgc.springboot.aviation.service.jianghongkun.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kgc.springboot.aviation.mapper.ConsultingMapper;
import com.kgc.springboot.aviation.pojo.Consulting;
import com.kgc.springboot.aviation.pojo.ConsultingExample;
import com.kgc.springboot.aviation.service.jianghongkun.ZixunService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * ClassName: zixunServiceImpl <br/>
 * Description: <br/>
 * date: 2021/1/11 14:42<br/>
 *
 * @author 12161<br />
 * @since JDK 1.8
 */
@Service
public class ZixunServiceImpl implements ZixunService {
    @Resource
    ConsultingMapper consultingMapper;
    @Override
    public PageInfo<Consulting> getConsultingList(String phone, String content, Integer pageNum, Integer pageSize) {
        System.out.println("进入到查询咨询列表方法");
        System.out.println("从前端获取的手机号为"+phone);
        System.out.println("从前端获取的内容为"+content);
        //设置起始页，页容量
        PageHelper.startPage(pageNum, pageSize);
        List<Consulting> consultingList = null;
        ConsultingExample consultingExample = new ConsultingExample();
        ConsultingExample.Criteria criteria = consultingExample.createCriteria();
        //第一种情况
        if ((phone != null && phone.length() > 0) && (content == null || content.equals(""))) {
            System.out.println("进入到第一种情况");
            criteria.andPhoneLike("%"+phone+"%");
        }
        //第二种情况
        if ((phone == null || phone.equals("")) && (content != null && content.length() > 0)){
            System.out.println("进入到第二种情况");
            criteria.andContentLike("%"+content+"%");
        }
        //第三种情况
        if ((phone != null && phone.length() > 0) && (content != null && content.length() >0)){
            System.out.println("进入到第三种情况");
            criteria.andPhoneLike("%"+phone+"%").andContentLike("%"+content+"%");
        }
        //第四种情况
        if ((phone == null && phone.length() == 0) && (content == null && content.length() ==0)){
            System.out.println("进入到第四种情况");
            //默认为空
            consultingExample=null;
        }
        System.out.println("开始查询");
        List<Consulting> consultingList1 = consultingMapper.selectByExample(consultingExample);
        if (consultingList1.size() > 0 && consultingList1 != null) {
            System.out.println("查询结果不为空");
            PageInfo<Consulting> pageInfo = new PageInfo<>(consultingList1);
            return pageInfo;
        }
        System.out.println("查询结果为空");
        return null;
    }
}
